﻿using GuestRoomMvc.Models;
using System.Web.Mvc;
using Guest_room.BLL;
using static System.Net.Mime.MediaTypeNames;
using System.Data;
using System.IO;
using System;

namespace GuestRoomMvc.Controllers
{
    public class CustomerInfoController : Controller
    {
        public CustomerInfoModel info;
        [HttpPost]
        public ActionResult DisplayInfo(string pro_id)
        {
            GuestRoomService guestRoomService = new GuestRoomService();
            var (dtCustomerDetails, dtStayInfo) = guestRoomService.GetCustomerInfo(pro_id);

            if (dtStayInfo.Rows.Count == 0)
            {
                ViewBag.message = "没有相关结果";
                return View();
            }
            // 获取客户身份证照片的相对路径
            string photoPath = dtCustomerDetails.Rows[0]["客户身份证照片"].ToString();
            // 获取当前请求的根URL
            string currentPath = @"C:\\Users\\Big.M\\OneDrive\\桌面\\01课程\\系统集成与应用-黄君强\\kese_src\\新建文件夹 (3)\\GuestRoom.UI\\bin\\Debug";
            // 将根URL与相对路径组合
            string fullPhotoPath = currentPath + Url.Content(Path.Combine("", photoPath));

            CustomerInfoModel customerInfo = new CustomerInfoModel
            {
                CustomerId = dtStayInfo.Rows[0]["客户编号"].ToString(),
                CustomerName = dtCustomerDetails.Rows[0]["客户姓名"].ToString(),
                CustomerGender = dtCustomerDetails.Rows[0]["客户性别"].ToString(),
                CustomerIdCard = dtCustomerDetails.Rows[0]["客户身份证"].ToString(),
                RoomId = dtStayInfo.Rows[0]["客房编号"].ToString(),
                CheckInDate = dtStayInfo.Rows[0]["入住日期"].ToString(),
                CheckOutDate = dtStayInfo.Rows[0]["退房日期"].ToString(),
                CheckInOfficer = dtCustomerDetails.Rows[0]["入住经办员"].ToString(),
                CheckOutOfficer = dtCustomerDetails.Rows[0]["退房经办员"].ToString(),
                ExpectedStayDuration = dtStayInfo.Rows[0]["预计入住时长"].ToString(),
                RoomAmount = dtStayInfo.Rows[0]["房间金额"].ToString(),
                CustomerPhotoPath = fullPhotoPath
            };

            return View(customerInfo);
        }


        // GET: CustomerInfo
        public ActionResult Index()
        {
            return View();
        }
    }
}
